package tbs.framework.utils;

import tbs.framework.interfaces.RunableWithThrows;

import java.util.function.Consumer;

/**
 * @author Abstergo
 */
public class TryCatchUtils {

    public static void tryCatch(RunableWithThrows runnable, Consumer<Throwable> error, Runnable finallyRunnable) {
        try {
            runnable.run();
        } catch (Throwable e) {
            if (error != null) {
                error.accept(e);
            }
        } finally {
            if (finallyRunnable != null) {
                finallyRunnable.run();
            }
        }
    }
}
